//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CashFlow.h"
using namespace Cephei::QL;
#include <gen/QL/Event.h>
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::CCashFlow::CCashFlow (boost::shared_ptr<QuantLib::CashFlow>& childNative, Object^ owner) : CEvent(CCashFlow::typeid)
{
#ifdef HANDLE
	_phCashFlow = NULL;
#endif
	_ppCashFlow = &childNative;
    _ppEvent = new boost::shared_ptr<QuantLib::Event> (boost::dynamic_pointer_cast<QuantLib::Event> (*_ppCashFlow));
}
Cephei::QL::CCashFlow::CCashFlow (QuantLib::CashFlow& childNative, Object^ owner) : CEvent(CCashFlow::typeid)
{
#ifdef HANDLE
	_phCashFlow = NULL;
#endif
	_ppCashFlow = new boost::shared_ptr<QuantLib::CashFlow> (&childNative);
    _ppEvent = new boost::shared_ptr<QuantLib::Event> (boost::dynamic_pointer_cast<QuantLib::Event> (*_ppCashFlow));
    _CashFlowOwner = owner;
    _EventOwner = owner;
}

Cephei::QL::CCashFlow::CCashFlow (CCashFlow^ copy) : CEvent(CCashFlow::typeid)
{
#ifdef HANDLE
	_phCashFlow = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCashFlow = new boost::shared_ptr<QuantLib::CashFlow> (copy->GetShared());
        _ppEvent = new boost::shared_ptr<QuantLib::Event> (boost::dynamic_pointer_cast<QuantLib::Event> (*_ppCashFlow));
    }
}
Cephei::QL::CCashFlow::CCashFlow (PLATFORM::Type^ t) : CEvent(CCashFlow::typeid)
{
#ifdef HANDLE
	_phCashFlow = NULL;
#endif
	if (!t->IsSubclassOf(CCashFlow::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::CCashFlow::CCashFlow (QuantLib::Handle<QuantLib::CashFlow>& childNative, Object^ owner)  : CEvent(CCashFlow::typeid)
{
	_phCashFlow = &childNative;
	_ppCashFlow = &static_cast<boost::shared_ptr<QuantLib::CashFlow>>(childNative.currentLink());
    _ppEvent = new boost::shared_ptr<QuantLib::Event> (boost::dynamic_pointer_cast<QuantLib::Event> (*_ppCashFlow));
    _CashFlowOwner = owner;
}
Cephei::QL::CCashFlow::CCashFlow (QuantLib::Handle<QuantLib::CashFlow> childNative)  : CEvent(CCashFlow::typeid)
{
	_phCashFlow = &childNative;
	_ppCashFlow = &static_cast<boost::shared_ptr<QuantLib::CashFlow>>(childNative.currentLink());
    _ppEvent = new boost::shared_ptr<QuantLib::Event> (boost::dynamic_pointer_cast<QuantLib::Event> (*_ppCashFlow));
}
#endif
#ifdef STRUCT
Cephei::QL::CCashFlow::CCashFlow (QuantLib::CashFlow childNative)  : CEvent(CCashFlow::typeid)
{
#ifdef HANDLE
	_phCashFlow = NULL;
#endif
	_ppCashFlow = new boost::shared_ptr<QuantLib::CashFlow> (new QuantLib::CashFlow (childNative));
    _ppEvent = new boost::shared_ptr<QuantLib::Event> (boost::dynamic_pointer_cast<QuantLib::Event> (*_ppCashFlow));
}
#endif

Cephei::QL::CCashFlow::~CCashFlow ()
{
    if (_ppCashFlow != NULL)
    {
	    delete _ppCashFlow;
        _ppCashFlow = NULL;
    }
}
Cephei::QL::CCashFlow::!CCashFlow ()
{
    if (_ppCashFlow != NULL)
    {
	    delete _ppCashFlow;
    }
}
QuantLib::CashFlow& Cephei::QL::CCashFlow::GetReference ()
{
    if (_ppCashFlow == NULL) throw REFNEW NativeNullException ();
	return **_ppCashFlow;
}
boost::shared_ptr<QuantLib::CashFlow>& Cephei::QL::CCashFlow::GetShared ()
{
    if (_ppCashFlow == NULL) throw REFNEW NativeNullException ();
	return *_ppCashFlow;
}
QuantLib::CashFlow* Cephei::QL::CCashFlow::GetPointer ()
{
    if (_ppCashFlow == NULL) throw REFNEW NativeNullException ();
	return &**_ppCashFlow;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CashFlow>& Cephei::QL::CCashFlow::GetHandle ()
{
	if (_phCashFlow == NULL)
	{
		_phCashFlow = new Handle<QuantLib::CashFlow> (*_ppCashFlow);
	}
	return *_phCashFlow;
}
#endif
bool Cephei::QL::CCashFlow::HasNative () 
{
	return (_ppCashFlow != NULL);
}

Boolean Cephei::QL::CCashFlow::HasOccurred (Microsoft::FSharp::Core::FSharpOption<DateTime>^ refDate, Microsoft::FSharp::Core::FSharpOption<Boolean>^ includeRefDate)
{
    try
    {
        QuantLib::Date _refDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (refDate) ? (QuantLib::Date)ValueHelper::Convert (refDate->Value) : QuantLib::Date()); //9a
        boost::optional<bool> _includeRefDate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (includeRefDate) ? boost::optional<bool> (ValueHelper::Convert (includeRefDate->Value)) : boost::optional<bool>()); //9
    	bool _rv = (bool)(*_ppCashFlow)->hasOccurred ( _refDate,  _includeRefDate );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::CCashFlow::Amount::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlow)->amount ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::CCashFlow::Date::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlow)->date ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::CCashFlowVector::CCashFlowVector ()
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
}
Cephei::QL::CCashFlowVector::~CCashFlowVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
	_pVValue = NULL;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
	_pVBoost = NULL;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
	_pVHand = NULL;
#endif
}
Cephei::QL::CCashFlowVector::!CCashFlowVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
#endif
}
#ifdef STRUCT
Cephei::QL::CCashFlowVector::CCashFlowVector (std::vector<QuantLib::CashFlow>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = &vec;
	_owner = owner;
}
Cephei::QL::CCashFlowVector::CCashFlowVector (std::vector<QuantLib::CashFlow> vec)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = new std::vector<QuantLib::CashFlow> (vec);
}
#endif
Cephei::QL::CCashFlowVector::CCashFlowVector (std::vector<boost::shared_ptr<QuantLib::CashFlow>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVBoost = &vec;
	_owner = owner;
}
#ifdef HANDLE
Cephei::QL::CCashFlowVector::CCashFlowVector (std::vector<QuantLib::Handle<QuantLib::CashFlow>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVHand = &vec;
	_owner = owner;
}
#endif

int Cephei::QL::CCashFlowVector::Count::get ()
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
		return _pVValue->size();
	}
#endif    
	if (_pVBoost != NULL)
	{
		return _pVBoost->size ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		return _pVHand->size ();
	}
#endif
	return 0;		// should never happen
}
Cephei::QL::ICashFlow^ Cephei::QL::CCashFlowVector::default::get (int index) 
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
    	if ((size_t)index >= _pVValue->size()) throw REFNEW RangeException ();
		QuantLib::CashFlow& native = (*_pVValue)[index];
		return REFNEW CCashFlow (native, this);
	}
#endif    
	if (_pVBoost != NULL)
	{
    	if ((size_t)index >= _pVBoost->size()) throw REFNEW RangeException ();
		QuantLib::CashFlow& native = *(*_pVBoost)[index];
		return REFNEW CCashFlow (native, this);
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
    	if ((size_t)index >= _pVHand->size()) throw REFNEW RangeException ();
		QuantLib::CashFlow& native = *((*_pVHand)[index].currentLink ());
		return REFNEW CCashFlow (native, this);
	}
#endif
	return nullptr;		// can never be the case
}
void Cephei::QL::CCashFlowVector::default::set (int index, Cephei::QL::ICashFlow^ value) 
{
#ifdef STRUCT
	if (_pVValue != NULL)
	{
		if (_pVValue->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVValue->size() < (size_t)index)
			{
				throw REFNEW RangeException ();
			}
			_pVValue->push_back (dynamic_cast<CCashFlow^>(value)->GetReference ());
		}
        else
        {
            QuantLib::CashFlow& c = (*_pVValue)[index];
            c = dynamic_cast<CCashFlow^>(value)->GetReference ();
        }
	}
#endif   
	if (_pVBoost != NULL)
	{
		if (_pVBoost->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVBoost->size() < (size_t)index)
			{
				throw REFNEW RangeException ();
			}
			_pVBoost->push_back (dynamic_cast<CCashFlow^>(value)->GetShared ());
		}
		boost::shared_ptr<QuantLib::CashFlow>& c = (*_pVBoost)[index];
		c = dynamic_cast<CCashFlow^>(value)->GetShared ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		if (_pVHand->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVHand->size() < (size_t)index)
			{
				throw REFNEW RangeException ();
			}
			_pVHand->push_back (QuantLib::Handle<QuantLib::CashFlow> ());
		}
		QuantLib::Handle<QuantLib::CashFlow>& c = (*_pVHand)[index];
		boost::shared_ptr<QuantLib::CashFlow>& b = static_cast<boost::shared_ptr<QuantLib::CashFlow>>(c.currentLink());
		b = dynamic_cast<CCashFlow^>(value)->GetShared ();
	}
#endif
}
Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlowVector::CItem::get (int index) 
{
	return CellFactory::Instance->Create<ICashFlow^> (dynamic_cast<ICashFlow^>(default[index]));
}

void Cephei::QL::CCashFlowVector::CItem::set (int index, Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^ value) 
{
	default[index] = safe_cast<ICashFlow^>(value->Value);
}
#ifdef STRUCT
std::vector<QuantLib::CashFlow>& Cephei::QL::CCashFlowVector::GetReference ()
{
	 return *_pVValue;
}
#endif

std::vector<boost::shared_ptr<QuantLib::CashFlow>>& Cephei::QL::CCashFlowVector::GetShared ()
{
	return *_pVBoost;
}

#ifdef HANDLE
std::vector<QuantLib::Handle<QuantLib::CashFlow>>& Cephei::QL::CCashFlowVector::GetHandle ()
{
	return *_pVHand;
}
#endif
bool Cephei::QL::CCashFlowVector::PrepareFeature (NativeFeature feature)
{
	switch (feature)
	{
#ifdef STRUCT
		case NativeFeature::Value :
			if (_pVValue == NULL)
			{
				_pVValue = new std::vector<QuantLib::CashFlow> ();
				return true;
			}
			break;
#endif
        case NativeFeature::shared_ptr :
			if (_pVBoost == NULL)
			{
				_pVBoost = new std::vector<boost::shared_ptr<QuantLib::CashFlow>> ();
				return true;
			}
			break;
#ifdef HANDLE
        case NativeFeature::Handle :
            if (_pVHand == NULL)
            {
                _pVHand = new std::vector<QuantLib::Handle<QuantLib::CashFlow>> ();
                return true;
            }
            break;
#endif
	}
	return false;
}
Cephei::QL::CCashFlowMatrix::CCashFlowMatrix ()
{
#ifdef STRUCT
	_pVValue = NULL;
#endif    
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
}
#ifdef STRUCT
Cephei::QL::CCashFlowMatrix::CCashFlowMatrix (std::vector<std::vector<QuantLib::CashFlow>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif    
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = &vec;
	_owner = owner;
}
Cephei::QL::CCashFlowMatrix::CCashFlowMatrix (std::vector<std::vector<QuantLib::CashFlow>> vec)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif    
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = new std::vector<std::vector<QuantLib::CashFlow>> (vec);
}
#endif
Cephei::QL::CCashFlowMatrix::CCashFlowMatrix (std::vector<std::vector<boost::shared_ptr<QuantLib::CashFlow>>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif    
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVBoost = &vec;
	_owner = owner;
}
#ifdef HANDLE
Cephei::QL::CCashFlowMatrix::CCashFlowMatrix (std::vector<std::vector<QuantLib::Handle<QuantLib::CashFlow>>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif    
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVHand = &vec;
	_owner = owner;
}
#endif
Cephei::QL::CCashFlowMatrix::~CCashFlowMatrix ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
	_pVValue = NULL;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
	_pVBoost = NULL;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
	_pVHand = NULL;
#endif
}
Cephei::QL::CCashFlowMatrix::!CCashFlowMatrix ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
	_pVValue = NULL;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
	_pVBoost = NULL;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
	_pVHand = NULL;
#endif
}
int Cephei::QL::CCashFlowMatrix::Count::get ()
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
		return _pVValue->size();
	}
#endif    
	if (_pVBoost != NULL)
	{
		return _pVBoost->size ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		return _pVHand->size ();
	}
#endif
	return 0;		// should never happen
}
Cephei::QL::ICashFlow^ Cephei::QL::CCashFlowMatrix::default::get (int x, int y) 
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
		if ((size_t)x >= _pVValue->size() || (size_t)y >= (*_pVValue)[x].size()) throw REFNEW RangeException ();
		QuantLib::CashFlow& native = (*_pVValue)[x][y];
		return REFNEW CCashFlow (native, this);
	}
#endif    
	if (_pVBoost != NULL)
	{
		if ((size_t)x >= _pVBoost->size() || (size_t)y >= (*_pVBoost)[x].size()) throw REFNEW RangeException ();
		QuantLib::CashFlow& native = *(*_pVBoost)[x][y];
		return REFNEW CCashFlow (native, this);
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		if ((size_t)x >= _pVHand->size() || (size_t)y >= (*_pVHand)[x].size()) throw REFNEW RangeException ();
		QuantLib::CashFlow& native = *((*_pVHand)[x][y].currentLink ());
		return REFNEW CCashFlow (native, this);
	}
#endif
	return nullptr;		// can never be the case
}
void Cephei::QL::CCashFlowMatrix::default::set (int x, int y, Cephei::QL::ICashFlow^ value) 
{
#ifdef STRUCT
	if (_pVValue != NULL)
	{
		if (_pVValue->size() <= (size_t)x)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVValue->size()-1 < (size_t)x) throw REFNEW RangeException ();

			_pVValue->push_back (std::vector<QuantLib::CashFlow>());
		}
		if ((*_pVValue)[x].size() <= (size_t)y)
		{
			if ((*_pVValue)[x].size() < (size_t)y) throw REFNEW RangeException ();

			(*_pVValue)[x].push_back (dynamic_cast<CCashFlow^>(value)->GetReference ());
		}
        else
        {    
            QuantLib::CashFlow& c = (*_pVValue)[x][y];
            c = dynamic_cast<CCashFlow^>(value)->GetReference ();
        }
	}
#endif    
	if (_pVBoost != NULL)
	{
		if (_pVBoost->size() <= (size_t)x)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVBoost->size()-1 < (size_t)x) throw REFNEW RangeException ();

			_pVBoost->push_back (std::vector<boost::shared_ptr<QuantLib::CashFlow>>());
		}
		if ((*_pVBoost)[x].size() <= (size_t)y)
		{
			if ((*_pVBoost)[x].size() < (size_t)y) throw REFNEW RangeException ();

			(*_pVBoost)[x].push_back (dynamic_cast<CCashFlow^>(value)->GetShared ());
		}
        else
        {
            boost::shared_ptr<QuantLib::CashFlow>& c = (*_pVBoost)[x][y];
            c = dynamic_cast<CCashFlow^>(value)->GetShared ();
        }
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		if (_pVHand->size() <= (size_t)x)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVHand->size()-1 < (size_t)x) throw REFNEW RangeException ();

			_pVHand->push_back (std::vector<QuantLib::Handle<QuantLib::CashFlow>>());
		}
		if ((*_pVHand)[x].size() <= (size_t)y)
		{
			if ((*_pVHand)[x].size() < (size_t)y) throw REFNEW RangeException ();

			(*_pVHand)[x].push_back (QuantLib::Handle<QuantLib::CashFlow> ());
		}
		QuantLib::Handle<QuantLib::CashFlow>& c = (*_pVHand)[x][y];
		boost::shared_ptr<QuantLib::CashFlow>& b = static_cast<boost::shared_ptr<QuantLib::CashFlow>>(c.currentLink());
		b = dynamic_cast<CCashFlow^>(value)->GetShared ();
	}
#endif
}
Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlowMatrix::CItem::get (int x, int y) 
{
	return CellFactory::Instance->Create<Cephei::QL::ICashFlow^> (dynamic_cast<ICashFlow^>(default[x,y]));
}
void Cephei::QL::CCashFlowMatrix::CItem::set (int x, int y, Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^ value)
{
	default[x,y] = safe_cast<ICashFlow^>(value->Value);
}

#ifdef STRUCT
std::vector<std::vector<QuantLib::CashFlow>>& Cephei::QL::CCashFlowMatrix::GetReference ()
{
	 return *_pVValue;
}
#endif

std::vector<std::vector<boost::shared_ptr<QuantLib::CashFlow>>>& Cephei::QL::CCashFlowMatrix::GetShared ()
{
	return *_pVBoost;
}

#ifdef HANDLE
std::vector<std::vector<QuantLib::Handle<QuantLib::CashFlow>>>& Cephei::QL::CCashFlowMatrix::GetHandle ()
{
	return *_pVHand;
}
#endif
bool Cephei::QL::CCashFlowMatrix::PrepareFeature (NativeFeature feature)
{
	switch (feature)
	{
#ifdef STRUCT
		case NativeFeature::Value :
			if (_pVValue == NULL)
			{
				_pVValue = new std::vector<std::vector<QuantLib::CashFlow>> ();
				return true;
			}
			break;
#endif            
		case NativeFeature::shared_ptr :
			if (_pVBoost == NULL)
			{
				_pVBoost = new std::vector<std::vector<boost::shared_ptr<QuantLib::CashFlow>>> ();
				return true;
			}
			break;
#ifdef HANDLE
		case NativeFeature::Handle :
			if (_pVHand == NULL)
			{
				_pVHand = new std::vector<std::vector<QuantLib::Handle<QuantLib::CashFlow>>> ();
				return true;
			}
			break;
#endif
	}
	return false;
}
INativeVector<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlowMatrix::CreateVector () 
{
	return REFNEW CCashFlowVector ();
}
INativeVector<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^ Cephei::QL::CCashFlowMatrix::CreateCellVector ()
{
	return REFNEW CCashFlowVector ();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

/* <summary>Create a single dimension array of CashFlow that can be passed into other function </summary> */
IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlow_Factory::CreateVector ()
 {
	 return REFNEW CoVector<ICashFlow^> (REFNEW CCashFlowVector ());
 }
IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlow_Factory::CreateVector (PLATFORM::Collections::Generic::IEnumerable<ICashFlow^>^ source)
 {
	 return REFNEW CoVector<ICashFlow^> (source, REFNEW CCashFlowVector ());
 }
/* <summary>Create a single dimension array of CashFlow with change events</summary> */
Cephei::Core::Generic::ICoCell<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^>^ Cephei::QL::CCashFlow_Factory::CreateCellVector ()
 {
	 return CellFactory::Instance->Create<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^> (REFNEW CoCellVector<Cephei::QL::ICashFlow^> (REFNEW CCashFlowVector ()));
 }
Cephei::Core::Generic::ICoCell<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^>^ Cephei::QL::CCashFlow_Factory::CreateCellVector (PLATFORM::Collections::Generic::IEnumerable<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^ source)
 {
	 return CellFactory::Instance->Create<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^> (REFNEW CoCellVector<Cephei::QL::ICashFlow^> (source, REFNEW CCashFlowVector ()));
 }

/* <summary> Create a two dimension array of CashFlow that can be passed into other function </summary> */
Cephei::Core::IMatrix<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlow_Factory::CreateMatrix ()
 {
	 return REFNEW CoMatrix<ICashFlow^> (REFNEW CCashFlowMatrix ());
 }
Cephei::Core::IMatrix<Cephei::QL::ICashFlow^>^ Cephei::QL::CCashFlow_Factory::CreateMatrix (PLATFORM::Collections::Generic::IEnumerable<PLATFORM::Collections::Generic::IEnumerable<ICashFlow^>^>^ source)
 {
	 return REFNEW CoMatrix<ICashFlow^> (source, REFNEW CCashFlowMatrix ());
 }
/* <summary> Create a two dimension array of CashFlow with change events </summary> */
Cephei::Core::Generic::ICoCell<Cephei::Core::IMatrix<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^>^ Cephei::QL::CCashFlow_Factory::CreateCellMatrix ()
 {
	 return CellFactory::Instance->Create<Cephei::Core::IMatrix<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^> (REFNEW CoCellMatrix<Cephei::QL::ICashFlow^> (REFNEW CCashFlowMatrix ()));
 }
Cephei::Core::Generic::ICoCell<Cephei::Core::IMatrix<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^>^ Cephei::QL::CCashFlow_Factory::CreateCellMatrix (PLATFORM::Collections::Generic::IEnumerable<PLATFORM::Collections::Generic::IEnumerable<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^>^ source)
 {
	 return CellFactory::Instance->Create<Cephei::Core::IMatrix<Cephei::Core::Generic::ICoCell<Cephei::QL::ICashFlow^>^>^> (REFNEW CoCellMatrix<Cephei::QL::ICashFlow^> (source, REFNEW CCashFlowMatrix ()));
 }

